home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11.lha / HBBS / Developer / Examples / ConfigFiles / configs.c next >
Text File  |  1996-07-15  |  1KB  |  59 lines

  1. // (C) 1996 Hydra/TSN/LSD
  2.  
  3. // example of reading items from a config file..
  4. // last updated: 15/07/1996
  5.  
  6. /* Here's an example config file:
  7.  
  8. --( CUT HERE )------------------------
  9.  
  10.       FrEd=A string ;skjjshdjskjksjk
  11.       num=83634
  12.       list_1=fred
  13.       list_2=sid
  14.       list_3=moocow
  15.  
  16.       bool=YES
  17. ;      bool=NO
  18. ;      bool=ON
  19. ;      bool=OFF
  20. ;      bool=TRUE
  21. ;      bool=FALSE
  22.  
  23. --( CUT HERE )------------------------
  24.  
  25. */
  26.  
  27.  
  28. void LoadCFG( void )
  29. {
  30.   struct CfgFileData *DeviceCFG;
  31.   V_ERROR error=TYPE_NONE;
  32.   UBYTE *filename="Progdir:Test.CFG";
  33.  
  34.   VTYPE_STRING mystring=NULL;          // ALWAYS INITILISE VARIABLES that you pass to HBBS_GetSetting to
  35.   VTYPE_STRINGLIST mylist=NULL;        // NULL or 0 otherwise you can expect a system crash!
  36.   VTYPE_BIGNUM mynum=0;
  37.   VTYPE_BOOL mybool=FALSE;
  38.  
  39.   if (DeviceCFG=HBBS_LoadConfig(filename,LCFG_NONE)))
  40.   {
  41.  
  42.     HBBS_GetSetting(DeviceCFG,(void *)&mystring,VTYPE_STRING    ,"fred",OPT_SINGLE);
  43.     HBBS_GetSetting(DeviceCFG,(void *)&mynum   ,VTYPE_BIGNUM    ,"num" ,OPT_SINGLE);
  44.     HBBS_GetSetting(DeviceCFG,(void *)&mylist  ,VTYPE_STRINGLIST,"list",OPT_MULTI);
  45.     HBBS_GetSetting(DeviceCFG,(void *)&mybool  ,VTYPE_BOOL      ,"bool",OPT_SINGLE);
  46.  
  47.     HBBS_FlushConfig(DeviceCFG);
  48.   }
  49.  
  50.   /*
  51.      you can now do stuff with the variables that have been loaded from
  52.      the config file as you would with any other variable
  53.   */
  54.  
  55.   // Don't forgetting to free them after use though
  56.   FreeStrList(mylist);
  57.   FreeStr(mystring);
  58. }
  59.